
from gstreamer_lib.GStreamerWrapper import GStreamerWrapper
import cv2

def main():
    print("Initializing GStreamerWrapper...")
    wrapper = GStreamerWrapper()

    # Wait for the first frame to be ready
    # The GStreamerWrapper's internal thread needs a moment to pull the first frame.
    print("Waiting for the first frame...")
    frame = None
    while frame is None:
        frame = wrapper.GetFrame()
    
    print("Frame successfully retrieved.")

    # Save the frame to a file
    file_name = "test_frame.jpg"
    cv2.imwrite(file_name, frame)
    print(f"Image saved as {file_name}")

    # Clean up the GStreamer pipeline and thread
    print("Stopping GStreamer thread...")
    wrapper.StopThread()
    print("Test complete.")

if __name__ == "__main__":
    main()